<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html> 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<link href="<%=request.getContextPath() %>/ext/resources/css/ext-all.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=request.getContextPath() %>/ext/ext-all.js"></script>
</head>
<script type="text/javascript">
	Ext.onReady(function(){
		var itemsPerPage = 10;
		var store=new Ext.data.Store({ 
			pageSize: itemsPerPage, 
			fields : [
				'dbid',
				'name',
				'shop.name',
				'refShopDbidshopDbid',
				'color.name',
				'refColorDbid',
				'configuration.name',
				'refConfigurationDbid',
				'unit.name',
				'refUnitDbid',
				'plannumber',
				'realnumber',
				'planunitprice',
				'planmoney',
				'realunitprice',
				'memo',
				{ name: 'createDate' , type : 'date' },
    		],
    		proxy : {  
   				type : 'ajax', 
				url : '<%=request.getContextPath() %>/purchase/listPurchase.action',
   				reader : { type : 'json',root : 'purchasePageBeans' ,totalProperty: 'totalProperty'}   
    		} , 
			autoLoad : false,  
   			timeout: 900000,
		}); 
		var gridPanel= Ext.create('Ext.grid.GridPanel', {
 			store: store,    
			selModel : Ext.create('Ext.selection.CheckboxModel',{   mode: 'SINGLE' }),
			columnLines: true,
			columns: [
					{ text :'dbid', flex : 1 , sortable : true , hidden : true , dataIndex :'dbid' },
					{ text :'name', flex : 1 , sortable : true , dataIndex :'name' },
					{ text :'Shop Name ', flex : 1 , sortable : true , dataIndex :'shop.name' },
					{ text :'refShopDbidshopDbid', flex : 1 , sortable : true , hidden : true , dataIndex :'refShopDbidshopDbid' },
					{ text :'颜色', flex : 1 , sortable : true , dataIndex :'color.name' },
					{ text :'refColorDbid', flex : 1 , sortable : true , hidden : true , dataIndex :'refColorDbid' },
					{ text :'Configuration Name ', flex : 1 , sortable : true , dataIndex :'configuration.name' },
					{ text :'refConfigurationDbid', flex : 1 , sortable : true , hidden : true , dataIndex :'refConfigurationDbid' },
					{ text :'单位', flex : 1 , sortable : true , dataIndex :'unit.name' },
					{ text :'refUnitDbid', flex : 1 , sortable : true , hidden : true , dataIndex :'refUnitDbid' },
					{ text :'plannumber', flex : 1 , sortable : true , dataIndex :'plannumber' },
					{ text :'realnumber', flex : 1 , sortable : true , dataIndex :'realnumber' },
					{ text :'planunitprice', flex : 1 , sortable : true , dataIndex :'planunitprice' },
					{ text :'planmoney', flex : 1 , sortable : true , dataIndex :'planmoney' },
					{ text :'realunitprice', flex : 1 , sortable : true , dataIndex :'realunitprice' },
					{ text :'备注', flex : 1 , sortable : true , dataIndex :'memo' },
					{ text :'createDate', flex : 1 , sortable : true , dataIndex :'createDate' , hidden : true , renderer:Ext.util.Format.dateRenderer('Y-m-d'), },
			],
			height: 350,
			width: 600,
			tbar: new Ext.Toolbar({
				height : '32' , autoWidth:true, autoShow:true,
				items:[
				{ xtype: 'button', text: 'Add',tooltip: 'Add New Row',
					handler:  function (){
						var popWindow = new Ext.Window({
							id : 'AddPurchaseWindow',
				    		width : 600,
				    		title : '新增一条记录.', 
				    		closable: true, 
				    		resizable: true,
				    		constrainHeader: true,
				    		modal: true,
				    	    plain: true, 
				    		layout : 'fit',
				    		x : 250, y : 100,
				    		items :[{
				    			xtype: 'form',
				    			layout: 'form',
				    			frame: true,
				    			bodyPadding: '2 2 0',
				    			fieldDefaults: {
				    				msgTarget: 'side',
				    				labelWidth: 75
				    			},
				    			defaultType: 'textfield',
				    			items :[
				    			 { 
				    					xtype: 'textfield',
				    					fieldLabel: 'name',
				    					name: 'name',
				    					id: 'name',
				    			 }, 
				    			 { 
				    					xtype: 'combo',
				    					store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/shop/listShop.action', reader : { type : 'json' , root : 'shopPageBeans'} } ,autoLoad: true },
				    					valueField:'dbid', 
				    					displayField:'name', 
				    				//	 blankText:'Please Select', 
				    				//	  editable : true , 
				    				//	 emptyText:'please Select', 
				    				//	 forceSelection: true, 
				    					fieldLabel: '门店',
				    					name: 'refShopDbidshopDbid',
				    					id: 'refShopDbidshopDbid',
				    			 }, 
				    			 { 
				    					xtype: 'combo',
				    					store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/color/listColor.action', reader : { type : 'json' , root : 'colorPageBeans'} } ,autoLoad: true },
				    					valueField:'dbid', 
				    					displayField:'name', 
				    				//	 blankText:'Please Select', 
				    				//	  editable : true , 
				    				//	 emptyText:'please Select', 
				    				//	 forceSelection: true, 
				    					fieldLabel: '颜色',
				    					name: 'refColorDbid',
				    					id: 'refColorDbid',
				    			 }, 
				    			 { 
				    					xtype: 'combo',
				    					store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/configuration/listConfiguration.action', reader : { type : 'json' , root : 'configurationPageBeans'} } ,autoLoad: true },
				    					valueField:'dbid', 
				    					displayField:'name', 
				    				//	 blankText:'Please Select', 
				    				//	  editable : true , 
				    				//	 emptyText:'please Select', 
				    				//	 forceSelection: true, 
				    					fieldLabel: '配置',
				    					name: 'refConfigurationDbid',
				    					id: 'refConfigurationDbid',
				    			 }, 
				    			 { 
				    					xtype: 'combo',
				    					store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/unit/listUnit.action', reader : { type : 'json' , root : 'unitPageBeans'} } ,autoLoad: true },
				    					valueField:'dbid', 
				    					displayField:'name', 
				    				//	 blankText:'Please Select', 
				    				//	  editable : true , 
				    				//	 emptyText:'please Select', 
				    				//	 forceSelection: true, 
				    					fieldLabel: 'Unit',
				    					name: 'refUnitDbid',
				    					id: 'refUnitDbid',
				    			 }, 
				    			 { 
				    					xtype: 'numberfield',
				    					fieldLabel: 'plannumber',
				    					name: 'plannumber',
				    					id: 'plannumber',
				    			 }, 
				    			 { 
				    					xtype: 'numberfield',
				    					fieldLabel: '串号',
				    					name: 'realnumber',
				    					id: 'realnumber',
				    			 }, 
				    			 { 
				    					xtype: 'numberfield',
				    					fieldLabel: 'planunitprice',
				    					name: 'planunitprice',
				    					id: 'planunitprice',
				    			 }, 
				    			 { 
				    					xtype: 'numberfield',
				    					fieldLabel: 'planmoney',
				    					name: 'planmoney',
				    					id: 'planmoney',
				    			 }, 
				    			 { 
				    					xtype: 'numberfield',
				    					fieldLabel: 'realunitprice',
				    					name: 'realunitprice',
				    					id: 'realunitprice',
				    			 }, 
				    			 { 
				    					xtype: 'textfield',
				    					fieldLabel: 'memo',
				    					name: 'memo',
				    					id: 'memo',
				    			 }, 
				    			 { 
				    					xtype: 'datefield',
				    					format: 'Y-m-d H:i:s',
				    					fieldLabel: 'createDate',
				    					name: 'createDate',
				    					id: 'createDate',
				    			 }, 
				    			],
				    			 buttons :[
				    			 { 
				    					xtype: 'button',
				    					text: 'Save',
				    					name: 'SaveAddBtn',
				    					id: 'SaveAddBtn',
				    					handler:  function (){ 
				    						     this.up('form').getForm().doAction('submit',{ 
				    					             url:'<%=request.getContextPath() %>/purchase/insertPurchase.action', 
				    					             method:'post', 
				    					             params:'', 
				    					             success:function(form,action){ 
				    					                 Ext.Msg.alert('新增成功',action.result.info); 
				    					                 popWindow.close(); 
				    					                 store.reload(); 
				    					             }, 
				    					             failure:function(e){ 
				    					           	  console.info( e); 
				    					                  Ext.Msg.alert('error','Fail��'); 
				    					             } 
				    					           }); 
				    					},
				    			 }, 
				    			 { 
				    					xtype: 'button',
				    					text: 'Reset',
				    					name: 'ResetAddBtn',
				    					id: 'ResetAddBtn',
				    					handler:  function (){  this.up('form').getForm().reset();},
				    			 }, 
				    			 { 
				    					xtype: 'button',
				    					text: 'Close',
				    					name: 'CloseAddBtn',
				    					id: 'CloseAddBtn',
				    					handler:  function (){  popWindow.close();},
				    			 }, 
				    			 ] 
				    		}]
				    	});
						popWindow.show();
					}
				} ,
				{ xtype: 'button', text: 'Update',tooltip: 'Update Row',
					handler:  function (){
						var grid = this.ownerCt.ownerCt; 
						var checkRecord = grid.getSelectionModel().getSelection(); 
						if (checkRecord.length != 0) {
							var popWindow = new Ext.Window({
								id : 'updateWindow',
				    			width : 600,
				    			title : '更新记录.', 
				    			closable: true, 
				    			resizable: true,
				    			constrainHeader: true,
				    			modal: true,
				    	   		plain: true, 
				    			layout : 'fit',
				    			x : 250, y : 100,
				    			items :[{
				    				xtype: 'form',
				    				id: 'updateForm',
				    				layout: 'form',
				    				frame: true,
				    				bodyPadding: '2 2 0',
				    				fieldDefaults: {
				    					msgTarget: 'side',
				    					labelWidth: 75
				    				},
				    				defaultType: 'textfield',
				    			items :[
				    			 { 
				    					xtype: 'numberfield',
				    					fieldLabel: '编号', hidden :true ,
				    					name: 'dbid',
				    					id: 'dbid',
				    					readOnly: true,
				    			 }, 
				    			 { 
				    					xtype: 'textfield',
				    					fieldLabel: 'name',
				    					name: 'name',
				    					id: 'name',
				    			 }, 
				    			 { 
				    					xtype: 'combo',
				    					store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/shop/listShop.action', reader : { type : 'json' , root : 'shopPageBeans'} } ,autoLoad: true },
				    					valueField:'dbid', 
				    					displayField:'name', 
				    				//	 blankText:'Please Select', 
				    				//	  editable : false, , 
				    				//	 emptyText:'please Select', 
				    				//	 forceSelection: true, 
				    					fieldLabel: 'Shop',
				    					name: 'refShopDbidshopDbid',
				    					id: 'refShopDbidshopDbid',
				    			 }, 
				    			 { 
				    					xtype: 'combo',
				    					store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/color/listColor.action', reader : { type : 'json' , root : 'colorPageBeans'} } ,autoLoad: true },
				    					valueField:'dbid', 
				    					displayField:'name', 
				    				//	 blankText:'Please Select', 
				    				//	  editable : false, , 
				    				//	 emptyText:'please Select', 
				    				//	 forceSelection: true, 
				    					fieldLabel: 'Color',
				    					name: 'refColorDbid',
				    					id: 'refColorDbid',
				    			 }, 
				    			 { 
				    					xtype: 'combo',
				    					store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/configuration/listConfiguration.action', reader : { type : 'json' , root : 'configurationPageBeans'} } ,autoLoad: true },
				    					valueField:'dbid', 
				    					displayField:'name', 
				    				//	 blankText:'Please Select', 
				    				//	  editable : false, , 
				    				//	 emptyText:'please Select', 
				    				//	 forceSelection: true, 
				    					fieldLabel: 'Configuration',
				    					name: 'refConfigurationDbid',
				    					id: 'refConfigurationDbid',
				    			 }, 
				    			 { 
				    					xtype: 'combo',
				    					store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/unit/listUnit.action', reader : { type : 'json' , root : 'unitPageBeans'} } ,autoLoad: true },
				    					valueField:'dbid', 
				    					displayField:'name', 
				    				//	 blankText:'Please Select', 
				    				//	  editable : false, , 
				    				//	 emptyText:'please Select', 
				    				//	 forceSelection: true, 
				    					fieldLabel: 'Unit',
				    					name: 'refUnitDbid',
				    					id: 'refUnitDbid',
				    			 }, 
				    			 { 
				    					xtype: 'numberfield',
				    					fieldLabel: 'plannumber',
				    					name: 'plannumber',
				    					id: 'plannumber',
				    			 }, 
				    			 { 
				    					xtype: 'numberfield',
				    					fieldLabel: 'realnumber',
				    					name: 'realnumber',
				    					id: 'realnumber',
				    			 }, 
				    			 { 
				    					xtype: 'numberfield',
				    					fieldLabel: 'planunitprice',
				    					name: 'planunitprice',
				    					id: 'planunitprice',
				    			 }, 
				    			 { 
				    					xtype: 'numberfield',
				    					fieldLabel: 'planmoney',
				    					name: 'planmoney',
				    					id: 'planmoney',
				    			 }, 
				    			 { 
				    					xtype: 'numberfield',
				    					fieldLabel: 'realunitprice',
				    					name: 'realunitprice',
				    					id: 'realunitprice',
				    			 }, 
				    			 { 
				    					xtype: 'textfield',
				    					fieldLabel: 'memo',
				    					name: 'memo',
				    					id: 'memo',
				    			 }, 
				    			 { 
				    					xtype: 'datefield',
				    					format: 'Y-m-d H:i:s',
				    					fieldLabel: 'createDate',
				    					name: 'createDate',
				    					id: 'createDate',
				    			 }, 
				    			],
				    			 buttons :[
				    			 { 
				    					xtype: 'button',
				    					text: 'Save',
				    					name: 'SaveUppdateBtn',
				    					id: 'SaveUppdateBtn',
				    					handler:  function (){ 
				    						     this.up('form').getForm().doAction('submit',{ 
				    					             url:'<%=request.getContextPath() %>/purchase/updatePurchase.action', 
				    					             method:'post', 
				    					             params:'', 
				    					             success:function(form,action){ 
				    					                 Ext.Msg.alert('更新成功',action.result.info); 
				    					                 popWindow.close(); 
				    					                 store.reload(); 
				    					             }, 
				    					             failure:function(e){ 
				    					           	  console.info( e); 
				    					                  Ext.Msg.alert('error','Fail��'); 
				    					             } 
				    					           }); 
				    					},
				    			 }, 
				    			 { 
				    					xtype: 'button',
				    					text: 'Reset',
				    					name: 'ResetUpdateBtn',
				    					id: 'ResetUpdateBtn',
				    					handler:  function (){  this.up('form').getForm().reset();},
				    			 }, 
				    			 { 
				    					xtype: 'button',
				    					text: 'Close',
				    					name: 'CloseAddBtn',
				    					id: 'CloseAddBtn',
				    					handler:  function (){  popWindow.close();},
				    			 }, 
				    			 ] 
				    			}]
				    		});
							popWindow.show();
							Ext.getCmp("updateForm").getForm().loadRecord(checkRecord[0]);
							Ext.getCmp("updateForm").getForm().findField("refShopDbidshopDbid").setValue( checkRecord[0].data["refShopDbidshopDbid"]);
							Ext.getCmp("updateForm").getForm().findField("refColorDbid").setValue( checkRecord[0].data["refColorDbid"]);
							Ext.getCmp("updateForm").getForm().findField("refConfigurationDbid").setValue( checkRecord[0].data["refConfigurationDbid"]);
							Ext.getCmp("updateForm").getForm().findField("refUnitDbid").setValue( checkRecord[0].data["refUnitDbid"]);
						}else{
							Ext.MessageBox.alert('错误提示','请至少�?择一条信�?');
				      }
				    }
				} , 
				{ xtype: 'button', text: 'Delete',tooltip: 'Delete Row',
					handler:  function (){
						var grid = this.ownerCt.ownerCt;
					 Ext.MessageBox.confirm('Confirm', '确定要删除该记录吗?',
							 function showResult(btn,text){
							 	if (btn == "yes"){
									var store = grid.getStore();
									var checkRecord = grid.getSelectionModel().getSelection();
									if (checkRecord.length != 0) {
										Ext.Ajax.request({
											url : '<%=request.getContextPath() %>/purchase/deletePurchase.action',
											params : { dbid : checkRecord[0].data["dbid"] },
											success : function(response, options) {},
										});
										store.remove(checkRecord);
									}else{
										Ext.MessageBox.alert('������ʾ','������ѡ��һ����Ϣ!');
				       				}
								}
							}
						);
					}
				}
			] 
		}) ,
		viewConfig : { forceFit : true, scrollOffset : 0 },
		dockedItems: [{ xtype: 'pagingtoolbar', store: store,  dock: 'bottom', displayInfo: true  }],
		title: 'Purchase List ',
		}); 
		var searchPanel = Ext.create('Ext.form.Panel', {
		    defaultType: 'textfield',
			layout: { type: 'column', align: 'stretch',padding: 5 },
			frame: true,
		    items: [{
		    	columnWidth:0.5,
				xtype: 'container',
				flex: 1,
				border:false, 
				layout: 'anchor',
				defaultType: 'textfield',
				items: [
				        {
							xtype : 'textfield',
		   					fieldLabel: 'Name',
		   					name: 'qryBeginStringName',
		   					id: 'qryBeginStringName',
		   					anchor:'95%'
				        },
				        {
							xtype: 'combo',
							store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/color/listColor.action', reader : { type : 'json' , root : 'colorPageBeans'} } ,autoLoad: true },
							valueField:'dbid', 
							displayField:'name', 
							fieldLabel: 'Color',
		   					anchor:'95%',
		   					name: 'qryBeginIntRefColorDbid',
		   					id: 'qryBeginIntRefColorDbid',
				        },
				        {
							xtype: 'combo',
							store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/unit/listUnit.action', reader : { type : 'json' , root : 'unitPageBeans'} } ,autoLoad: true },
							valueField:'dbid', 
							displayField:'name', 
							fieldLabel: 'Unit',
		   					anchor:'95%',
		   					name: 'qryBeginIntRefUnitDbid',
		   					id: 'qryBeginIntRefUnitDbid',
				        },
				        {
							xtype : 'numberfield',
		   					fieldLabel: 'Realnumber',
		   					anchor:'95%',
		   					name: 'qryBeginIntRealnumber',
		   					id: 'qryBeginIntRealnumber',
				        },
				        {
							xtype : 'datefield',
							format: 'Y-m-d',
		   					fieldLabel: 'CreateDate End',
		   					name: 'qryEndDateCreateDate',
		   					id: 'qryEndDateCreateDate',
		   					anchor:'95%'
				        },
				]
			},{
				columnWidth:0.5,
				xtype: 'container',
				flex: 1,
				layout: 'anchor', 
				defaultType: 'textfield',
				items: [
				        {
							xtype: 'combo',
							store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/shop/listShop.action', reader : { type : 'json' , root : 'shopPageBeans'} } ,autoLoad: true },
							valueField:'dbid', 
							displayField:'name', 
							fieldLabel: 'Shop',
		   					anchor:'95%',
		   					name: 'qryBeginIntRefShopDbidshopDbid',
		   					id: 'qryBeginIntRefShopDbidshopDbid',
				        },
				        {
							xtype: 'combo',
							store: { xtype :'Ext.data.Store', fields:['dbid','name'],proxy :{ type:'ajax',url:'<%=request.getContextPath() %>/configuration/listConfiguration.action', reader : { type : 'json' , root : 'configurationPageBeans'} } ,autoLoad: true },
							valueField:'dbid', 
							displayField:'name', 
							fieldLabel: 'Configuration',
		   					anchor:'95%',
		   					name: 'qryBeginIntRefConfigurationDbid',
		   					id: 'qryBeginIntRefConfigurationDbid',
				        },
				        {
							xtype : 'numberfield',
		   					fieldLabel: 'Plannumber',
		   					anchor:'95%',
		   					name: 'qryBeginIntPlannumber',
		   					id: 'qryBeginIntPlannumber',
				        },
				        {
							xtype : 'textfield',
		   					fieldLabel: 'Memo',
		   					name: 'qryBeginStringMemo',
		   					id: 'qryBeginStringMemo',
		   					anchor:'95%'
				        },
				        {
							xtype : 'datefield',
							format: 'Y-m-d',
		   					fieldLabel: 'CreateDate From',
		   					name: 'qryBeginDateCreateDate',
		   					id: 'qryBeginDateCreateDate',
		   					anchor:'95%'
				        },
		{
	xtype :'checkbox',
	fieldLabel: 'Enable Like',
	name: 'qryLikeEnable',
	id : 'qryLikeEnable',
	anchor:'95%'
}
				]
			}]
			,
			buttons: [{
		        text: ' Search ',
		        handler: function() {
		            store.load();
		        }
		    },{
		        text: ' Reset ',
		        handler: function() {
		            this.up('form').getForm().reset();
		        }
		    }]
		 });
		store.load({
			params : {
				//username : username,
				start:0 ,
				limit: itemsPerPage 
 			}
		});
 		store.on('beforeload',function(){
	 		Ext.apply(  store.proxy.extraParams, {
				qryLikeEnable : Ext.getCmp("qryLikeEnable").getValue(),
				qryBeginStringName : Ext.getCmp("qryBeginStringName").getValue(),
				qryBeginIntRefShopDbidshopDbid : Ext.getCmp("qryBeginIntRefShopDbidshopDbid").getValue(),
				qryBeginIntRefColorDbid : Ext.getCmp("qryBeginIntRefColorDbid").getValue(),
				qryBeginIntRefConfigurationDbid : Ext.getCmp("qryBeginIntRefConfigurationDbid").getValue(),
				qryBeginIntRefUnitDbid : Ext.getCmp("qryBeginIntRefUnitDbid").getValue(),
				qryBeginIntPlannumber : Ext.getCmp("qryBeginIntPlannumber").getValue(),
				qryBeginIntRealnumber : Ext.getCmp("qryBeginIntRealnumber").getValue(),
				qryBeginStringMemo : Ext.getCmp("qryBeginStringMemo").getValue(),
				qryBeginDateCreateDate : Ext.getCmp("qryBeginDateCreateDate").getRawValue(),
				qryEndDateCreateDate : Ext.getCmp("qryEndDateCreateDate").getRawValue(),
			})
		});
		var mainPanel =Ext.create('Ext.panel.Panel', {
			id : 'purchaseMainPanel',
			layout: { type: 'vbox', align: 'stretch',padding: 5 },
			items: [ searchPanel , gridPanel  ],
			renderTo: Ext.getBody(),
		})
	});
</script>
